package com.chj.design.sk;

public class Code12_Adapter {
	public interface Bird {
		public void fly();
	}

	public static class Swallow implements Bird {
		@Override
		public void fly() {
			System.out.println("燕子在飞....");
		}
	}

	public static class WildGoose {
		public void wildGooseFly() {
			System.out.println("大雁在飞...");
		}
	}

//	类适配器就是使用继承来实现两个类之间的适配的
	public static class Adapter extends WildGoose implements Bird {
		@Override
		public void fly() {
			super.wildGooseFly();
		}
	}

//	对象适配器是在适配器中持有要匹配类的对象
	public static class Adapter02 implements Bird {
		WildGoose wildGoose = new WildGoose();

		@Override
		public void fly() {
			wildGoose.wildGooseFly();
		}
	}

//	https://blog.csdn.net/rocketeerLi/article/details/81813239
	public static void main(String[] args) {
		{
			Bird swallow = new Swallow();
			swallow.fly();
			Bird wildGoose = new Adapter();
			wildGoose.fly();
		}

		{
			Bird swallow = new Swallow();
			swallow.fly();
			Bird wildGoose = new Adapter02();
			wildGoose.fly();
		}
	}
}
